#include <bits/stdc++.h>
// 2025/04/04
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, m, p, a[1001], dp[1001], g[1001][1001];

class Queue{
private:
    queue<pair<int, int>> q;
public:
    void push(int x, int p)
    {
        while (!q.empty() && q.front().first <= x)
            q.pop();
        q.push({ x, p });
    }
    void pop(int x)
    {
        while (!q.empty() && q.front().second <= x)
            q.pop();
    }
    int front()
    {
        return q.front().first;
    }
};

Queue q[1001];

int loop(int x, int k)
{
    return ((x - k) % n + n) % n;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> p;
    for (int i = 0; i < n; i++)
        for (int j = 1; j <= m; j++)
            cin >> g[i][j];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int j = 2; j <= m; j++)
        for (int i = 0; i < n; i++)
            g[i][j] += g[loop(i, 1)][j - 1];
    for (int i = 0; i < n; i++)
        q[loop(i, -1)].push(-a[i], 0);
    for (int i = 1; i <= m; i++) {
        dp[i] = -1e9;
        for (int j = 0; j < n; j++)
            dp[i] = max(dp[i], g[loop(j, 1)][i] + q[loop(j, i - 1)].front());
        for (int j = 0; j < n; j++)
            q[loop(j, i - 1)].pop(i - p), q[loop(j, i - 1)].push(dp[i] - g[loop(j, 1)][i] - a[j], i);
    }
    cout << dp[m] << endl;
    return 0;
}